// pages/forward/forward.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ubNumber: 0,
        showbtn: true,
        money: '',
        
    },
    onLoad: function (options) {
      var uid = wx.getStorageSync('userId');
      if (!uid) {
        wx.redirectTo({
          url: '../wxauth/wxauth',
        })
      }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function(options) {
        var that = this;
        var uid = wx.getStorageSync('userId');
        wx.request({
          url: app.globalData.hostUrl + 'member/getfansinfo',
            data: {
              id: uid
            },
            success: function(res) {
//                console.log(res);
                var ubi = res.data.result.money;
                var bankno = res.data.result.bankno;
                var bankaddr = res.data.result.bankaddr;
                that.setData({
                    ubNumber: ubi,
                })
                
                if (bankno == '' || bankaddr=='') {
                    wx.showModal({
                        content: '对不起，请先填写【个人资料】中的银行卡信息！',
                        showCancel: false,
                        success: function (res) {
                            if (res.confirm) {
                                that.setData({
                                    showbtn: false,
                                })
                                wx.navigateTo({
                                  url: '../myself/info',
                                })
                            }
                        }
                    });
                }
                if (parseFloat(ubi) < 100) {
                  wx.showModal({
                    content: '对不起，目前您余额小于100元，不能提现！',
                    showCancel: false,
                    success: function (res) {
                      if (res.confirm) {
                        that.setData({
                          showbtn: false,
                        })
                      }
                    }
                  });
                }
            }
        })
    },
  
    formSubmit: function(e) {
        var that = this;
        var uid = wx.getStorageSync('userId');
        var money = e.detail.value.money;
      if (Number(money) == 0 || money==''){
            wx.showModal({
                content: '对不起，请输入提现金额',
                showCancel: false
            });
            return false;
        }
        wx.request({
            url: app.globalData.hostUrl + 'member/Foward',
            data: {
                txmoney: money,
                formid: e.detail.formId,
                uid: uid,
                openid: wx.getStorageSync("openId")
            },
            success: function(res) {
//                console.log(res);
                if(res.data.code==200){
                    wx.showModal({
                        content: '恭喜您，提现申请已提交，请耐心等待审核！',
                        showCancel: false
                    });
                    var nowubi = Number(that.data.ubNumber) - Number(money);
                    that.setData({
                        ubNumber:nowubi
                    })
                }
                else{
                  wx.showModal({
                    content: '对不起，提现申请失败',
                    showCancel: false
                  });
                  return false;
                }
            }
        })
    }

})